from django.conf import settings

from django.db import models
from malonghui.utils.models import BaseModel


class Question(BaseModel):
    """问题模型类"""
    user = models.ForeignKey('users.User', verbose_name='用户id', on_delete=models.CASCADE)
    title = models.CharField(max_length=30, unique=True, verbose_name='标题', default='')
    content = models.TextField(verbose_name='问题内容')
    visit_count = models.IntegerField(verbose_name="浏览量")
    solve = models.BooleanField(default=False, verbose_name='是否解决')
    is_deleted = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        db_table = 'tb_question'
        verbose_name = '问题'
        verbose_name_plural = verbose_name


class Answer(BaseModel):
    """答案模型类"""
    user = models.ForeignKey('users.User', on_delete=models.CASCADE, verbose_name='用户id')
    question = models.ForeignKey(Question, on_delete=models.CASCADE, verbose_name='问题id')
    content = models.TextField(verbose_name='内容')
    parent = models.ForeignKey('self', verbose_name='父评论id')
    paise_count = models.IntegerField(verbose_name='好评数')
    is_deleted = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        db_table = 'tb_password'
        verbose_name = '问题答案'
        verbose_name_plural = verbose_name
        ordering = ['-update_time']


class Flag(models.Model):
    """大标签模型类"""
    flag_name = models.CharField(max_length=10, verbose_name='标签名称')
    flag_detail = models.TextField(verbose_name='标签详情')
    question = models.ForeignKey(Question, on_delete=models.CASCADE, verbose_name='问题id')
    # news=models.ForeignKey('news.New',on_delete=models.CASCADE,verbose_name='新闻标签')
    f_like_count = models.IntegerField(verbose_name='标签关注量')
    is_deleted = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        db_table = 'tb_flag'
        verbose_name = '大标签'
        verbose_name_plural = verbose_name


class FlagLike(BaseModel):
    """用户关注标签"""
    user = models.ForeignKey('users.User', on_delete=models.CASCADE, verbose_name='用户id')
    flag = models.ForeignKey(Flag, on_delete=models.CASCADE, verbose_name='标签id')

    class Meta:
        db_table = 'tb_flag_lk'
        verbose_name = '标签关注'
        verbose_name_plural = verbose_name


class Categroy(BaseModel):
    """标签子类"""
    name = models.CharField(max_length=15, verbose_name="子标签名称")
    flag = models.ForeignKey(Flag, on_delete=models.CASCADE, verbose_name='大标签id')

    class Meta:
        db_table = 'tb_category'
        verbose_name = '子标签'
        verbose_name_plural = verbose_name
